package com.wb.Super;

/**
 * @author 黄衡熙
 * @version 1.0
 * @date 2025年07月21日10:45
 */
public class Pet {
    private String name;
    private int age;

    public Pet() {
        System.out.println("这是父类Pet的无参构造方法");
    }

    public Pet(String name) {
        System.out.println("这是父类Pet的name参数的构造方法");
        this.name = name;
    }

    public Pet(String name, int age) {
        System.out.println("这是父类Pet的两个参数的构造方法");
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

class Dog extends Pet {
    private String gender;
    private String name;

    public void show() {
        // 当子类与父类存在同名属性时,默认访问的是子类自己的
        System.out.println("name:" + name);
        System.out.println("name:" + getName());
        System.out.println("age:" + getAge());
        System.out.println("gender:" + gender);
        // 如果想要访问父类的,则可以通过super.属性名/方法名的方式进行访问
        System.out.println("父类name:" + super.getName());
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }

    public Dog(String name, int age, String gender) {
        // super(name,age)表示调用父类中参数分别是name与age类型的构造方法
        super(name, age);
        // 如果没有使用super关键字,则默认调用的是父类的无参构造方法
        System.out.println("这是子类构造方法");
        this.gender = gender;
    }

    public Dog(String name, int age, String gender, String name1) {
        super(name, age);
        this.gender = gender;
        this.name = name1;
    }

    public Dog() {
        super();
        System.out.println("这是子类Dog的无参构造方法");
    }
}
